#include "ZlgCan.h"
#include <iostream>
#include <stdio.h>

int main(int argc,char ** argv)
{
	ZlgCan::ZlgCan can;

	if (argc == 1)
	{
		std::cout << "ZLGCan CLI Tools" << std::endl;
		auto code = can.Open();
		if (code == ZlgCan::ZlgErrorCode::SUCCEED)
		{
			std::cout << "usbcanfd-200u is connected, your can send canframe now!" << std::endl << std::endl;
			std::cout << "Usages: zlgcan.exe canid canframe" << std::endl;
			std::cout << "Examps: zlgcan.exe 0x12d \"00 00 00 00 04 00 00 00\"" << std::endl;
		} else {
			std::cout << "start usbcanfd-200u failed, check your can device" << std::endl << std::endl;
		}
		if (code != ZlgCan::ZlgErrorCode::ERROR_OPEN_DEVICE_FAILED)
		{
			can.Close();
			return 0;
		}
	} else if (argc == 3)
	{
		char *id = argv[1];
		char *frame = argv[2];

		uint32_t canid = 0;
    	sscanf(id, "%x", &canid);

		auto code = can.Open();
		if (code == ZlgCan::ZlgErrorCode::SUCCEED)
		{
			code = can.Send(canid, frame);

		} else {
			std::cout << "start usbcanfd-200u failed, check your can device" << std::endl;
		}
		if (code != ZlgCan::ZlgErrorCode::ERROR_OPEN_DEVICE_FAILED)
		{
			can.Close();
			return 0;
		}

	} else {
		std::cout << "Wrong argc!!!" << std::endl;
		return -1;
	}
}